<?php
require("general_include.php");
$action = $_REQUEST['action'];

if($action == 'populateCity')
{
            $CitySql = "SELECT city_id, city_key FROM ".TABLEPREFIX."_cities WHERE city_name LIKE '".$_POST['data']."%' 
			ORDER BY city_name LIMIT 0,20";
			$CityArr = $AdminManagerObjAjax->GetRecords("All",$CitySql);
	
			$dataList = array();
	
			foreach ($CityArr as $row)
			{
				$toReturn   = html_entity_decode(htmlentities($row['city_key']));
				$dataList[] = '<li id="' .$row['city_id'] . '"><a href="javascript:;">' . $toReturn . '</a></li>';
			}
			
			if (count($dataList)>=1)
			{
				$dataOutput = join("\r\n", $dataList);
				echo $dataOutput;
			}
			else
			{
				echo '<li><a href="javascript:;">No Results</a></li>';
			}
}
if($action == 'populateCountry')
{
     $adSql = "SELECT country_id FROM ".TABLEPREFIX."_city WHERE city_id='".$_REQUEST['cityid']."'";
	 $adArr = $AdminManagerObjAjax->GetRecords("Row",$adSql);
	 
	// $citySql = "SELECT * FROM ".TABLEPREFIX."_city WHERE city_id='".$adArr['add_city_id']."'";
	// $cityArr = $UserManagerObjAjax->GetRecords("Row",$citySql);
	 
	$countrySql = "SELECT country_id,country_name FROM ".TABLEPREFIX."_country ORDER BY country_name";
    $CountryArr = $AdminManagerObjAjax->GetRecords("All",$countrySql);
	$str = '<select name="country" id="country" class="selectbox con-req">
			<option value="">Select</option>';
	$NumCoun=count($CountryArr);
	
	for($i=0;$i<$NumCoun;$i++)
	{		
       $sel = $adArr[0] == $CountryArr[$i]['country_id'] ? "selected" : "";
	   $str.='<option value="'.$CountryArr[$i]['country_id'].'" '.$sel.'>'.$CountryArr[$i]['country_name'].'</option>';
    
    }
	$str.='</select>';
	 echo $str;

}
if($action == 'populateUser')
{
            $UserSql = "SELECT user_id, name FROM ".TABLEPREFIX."_user WHERE name LIKE '".$_POST['data']."%' AND user_id!='".$_SESSION['user_id']."'
			ORDER BY name";
			$UserArr = $AdminManagerObjAjax->GetRecords("All",$UserSql);
	
			$dataList = array();
	
			foreach ($UserArr as $row)
			{
				$toReturn   = $row['name'];
				$dataList[] = '<li id="' .$row['user_id'] . '"><a href="javascript:;">' . htmlentities($toReturn) . '</a></li>';
			}
			
			if (count($dataList)>=1)
			{
				$dataOutput = join("\r\n", $dataList);
				echo $dataOutput;
			}
			else
			{
				echo '<li><a href="javascript:;">No Results</a></li>';
			}
}	
if($action == 'populateInfo')
{
         
			   $proSql = "SELECT * FROM ".TABLEPREFIX."_user WHERE user_id ='".$_REQUEST['studentid']."'";
			   $proArr = $AdminManagerObjAjax->GetRecords("Row",$proSql);
			   $str.='<label>User :</label>';
			   if($proArr['photo']!='')
				$str.='<img src="uploaded/user_images/thumbs/small_'.$proArr['photo'].'">&nbsp;&nbsp;';
				$Sqltype = "SELECT * FROM ".TABLEPREFIX."_user_type_user_relation WHERE user_id='".$_REQUEST['studentid']."'";
				$typeArr = $AdminManagerObjAjax->GetRecords("All",$Sqltype);
				$Numtype = count($typeArr);
				
				for($t=0;$t<$Numtype;$t++)
				{
				   if($typeArr[$t]['user_type_id']==1)
					  $type1 = 'Coach';
				   if($typeArr[$t]['user_type_id']==3)
					  $type2 = 'Training Partner';
				   if($typeArr[$t]['user_type_id']==2)
					  $type3 = 'Student'; 
				} 
				$str.=$type1. $type2. $type3;
		  
			 	
		   echo $str;   
		   

}
if($action == 'CountryId')
{
  $country = $_REQUEST['country'];
   $str =" $.fn.autosugguest({  
           className: 'ausu-suggest',
          methodType: 'POST',
            minChars: 2,
              rtnIDs: true,
		    dataFile: 'autocomplete.php?action=populateCity&country_id=".$country."'
       });";
   echo $str;	   
}
		
?>			